/**
 * 用户管理
 */
import { mapActions, mapState } from 'vuex'
import * as userAct from '@modules/user/MutationTypes'
export default {
  computed: {
    ...mapState('user', ['userInfo', 'departments'])
  },
  watch: {
    userInfo () {
      this.$emit('$_userInfoOk')
    },
    departments () {
      this.$emit('$_departmentsOk')
    }
  },
  methods: {
    ...mapActions('user', {
      setUserInfo: userAct.SET_USER_INFO
    }),
    $_getUserInfo () { // 监听vuex变化，赋值userInfo
      return new Promise(resolve => {
        if (!this.$lodash.isEmpty(this.userInfo)) {
          resolve(this.userInfo)
        } else {
          this.$once('$_userInfoOk', () => {
            resolve(this.userInfo)
          })
        }
      })
    },
    $_getDepartments () { // 监听vuex变化，赋值departments
      return new Promise(resolve => {
        if (!this.$lodash.isEmpty(this.departments)) {
          resolve(this.departments)
        } else {
          this.$once('$_departmentsOk', () => {
            resolve(this.departments)
          })
        }
      })
    }
  }
}
